﻿using UnityEngine;
using System.Collections;

public class Platform : MonoBehaviour {

	public Vector2 speed = new Vector2(0f, 1.7f);

	private Transform _transform = null;
	private Rigidbody2D _rigidbody = null;

	private Vector2 _targetPosition = new Vector3(0f, 10f);

	public Vector2 velocity {
		set {
			this.speed = value;
			this._rigidbody.velocity = speed;
		}
		get { return this._rigidbody.velocity; }
	}

	public Transform cachedTransform { get { return this._transform; } }

	public Vector2 position {
		get { return this._transform.localPosition; }
		set { this._transform.localPosition = value; }
	}

	void Awake() {
		this._rigidbody = this.rigidbody2D;
		this._transform = this.transform;
		this._targetPosition.x = this._transform.localPosition.x;
	}

	void Start() {
	}

	void Update() {
		if (this._transform.localPosition.y > 6) {
			PlatformManager.Instance.RecyclePlatform(this);
		}
		if (this.velocity != this.speed) this.velocity = this.speed;
	}
}
